﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Add-Subscription.aspx.cs" Inherits="Add_Subscription" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <link href="css/style-metro.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box yellow">
                <div class="portlet-title">
                    <div class="caption">
                        <asp:Label runat="server" ID="lblHeader" Text="Add/Edit Subscription"></asp:Label></div>
                </div>
                <div class="portlet-body form">
                    <div id="divMessage" runat="server" class="generalMessage">
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="planName">
                                <label class="control-label">
                                    <span class="Required">*</span>Plan Name</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtSubscriptionName" CssClass="span12  pName"></asp:TextBox>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="planAmount">
                                <label class="control-label">
                                    <span class="Required">*</span>Amount</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtAmount" CssClass="span12  pAmount" onkeypress="return allowPositiveNo(event);"></asp:TextBox>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="planDuration">
                                <label class="control-label">
                                    <span class="Required">*</span>Duration(In Month)</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtDuration" CssClass="span12  pDuration" onkeypress="return allowPositiveNo(event);"
                                        MaxLength="2"></asp:TextBox>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="Div1">
                                <label class="control-label">
                                    <span class="Required"></span>Description</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" TextMode="MultiLine" ID="txtDescription" CssClass="span12  pDuration" 
                                      ></asp:TextBox>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        <asp:Button ID="btnSave1" runat="server" OnClick="Save" Text="Save" CssClass="btn blue frmValidation" />
                        <asp:Button ID="btnCancel" runat="server" OnClick="Save" Text="Cancel" PostBackUrl="~/Subscription-List.aspx" CssClass="btn" />
                    </div>
                </div>
            </div>
        </div>
        <!-- END PAGE CONTENT-->
    </div>
    <script type="text/javascript">
        var msg = "Please check your validations in red.";
        $('.frmValidation').click(function () {

            var isError = "false";

            if ($('.pName').val() == "") {
                $('.pName').closest("div #planName").addClass("error");
                isError = "true";
            }
            else {
                $('.pName').closest("div #planName").removeClass("error");

            }
            if ($('.pDuration').val() == "") {
                $('.pDuration').closest("div #planDuration").addClass("error");
                isError = "true";
            }
            else {
                var data = $('.pDuration').val();
                var r = checkNumeric(data);

                if (r == false) {
                    $('.pDuration').closest("div #planDuration").addClass("error");
                    isError = "true";
                }
                else {
                    $('.pDuration').closest("div #planDuration").removeClass("error");
                }
            }
            if ($('.pAmount').val() == "") {
                $('.pAmount').closest("div #planAmount").addClass("error");
                isError = "true";
            }
            else {
                var data = $('.pAmount').val();
                var r = checkNumeric(data);

                if (r == false) {
                    $('.pAmount').closest("div #planAmount").addClass("error");
                    isError = "true";
                }
                else {
                    $('.pAmount').closest("div #planAmount").removeClass("error");
                }
            }

            if (isError == "true") {
                $(".generalMessage").html("<strong>Error!</strong> " + msg);
                $(".generalMessage").addClass("alert alert-danger");
                return false;
            }

        });
        function checkNumeric(data) {
            var len = data.length;
            var c;
            for (var i = 0; i < len; i++) {
                c = data.charAt(i).charCodeAt(0);
                if (c < 48 || c > 57) {
                    isError = "true";
                    return false;
                    break;
                }
                else {
                    return true;
                }
            }
        }
        function allowPositiveNo(evt) {

            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }
    </script>
</asp:Content>
